package com.deyuanyun.pic.ctrl.controller.vo.exinsp;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.NumberUtil;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.domain.ExinspSoilCorr;
import com.deyuanyun.pic.ctrl.enumeration.CurrentFerenceEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.math.BigDecimal;

/**
 * 土壤腐蚀性评价
 */
public class ExinspSoilCorrVO extends ExinspBaseVO<ExinspSoilCorr> {

    // 管道名称
    private String pipeLineName;
    // 测试桩编号
    private String testStationNum;
    // 土壤电阻率Ω·m
    private BigDecimal soilResistivity;
    // 土壤腐蚀性等级（弱中强）
    private String soilCorrosionRate;
    // 绝对距离
    private BigDecimal mileage;
    // 附近测试桩
    private String nagm;
    // 附近测试桩距离
    private BigDecimal nagmMileage;
    // 检测日期
    private String testingDate;
    // 检测单位
    private String testingCompany;

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getTestStationNum() {
        return testStationNum;
    }

    public void setTestStationNum(String testStationNum) {
        this.testStationNum = testStationNum;
    }

    public BigDecimal getSoilResistivity() {
        return soilResistivity;
    }

    public void setSoilResistivity(BigDecimal soilResistivity) {
        this.soilResistivity = soilResistivity;
    }

    public String getSoilCorrosionRate() {
        return soilCorrosionRate;
    }

    public void setSoilCorrosionRate(String soilCorrosionRate) {
        this.soilCorrosionRate = soilCorrosionRate;
    }

    public BigDecimal getMileage() {
        return mileage;
    }

    public void setMileage(BigDecimal mileage) {
        this.mileage = mileage;
    }

    public String getNagm() {
        return nagm;
    }

    public void setNagm(String nagm) {
        this.nagm = nagm;
    }

    public BigDecimal getNagmMileage() {
        return nagmMileage;
    }

    public void setNagmMileage(BigDecimal nagmMileage) {
        this.nagmMileage = nagmMileage;
    }

    public String getTestingDate() {
        return testingDate;
    }

    public void setTestingDate(String testingDate) {
        this.testingDate = testingDate;
    }

    public String getTestingCompany() {
        return testingCompany;
    }

    public void setTestingCompany(String testingCompany) {
        this.testingCompany = testingCompany;
    }

    EQPTBaseService eqptBaseService = SpringAppliction.getBean(EQPTBaseService.class);

    public void fromDomain(ExinspSoilCorr domain) {

        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 测试桩编号
        EqptCptestStation eqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getTestStationId());
        this.testStationNum = eqptCptestStation==null ? null : eqptCptestStation.getCustomNumber();
        // 土壤电阻率Ω·m
        this.soilResistivity = domain.getSoilResistivity();
        // 土壤腐蚀性等级（弱中强）
        this.soilCorrosionRate = CurrentFerenceEnum.getLabelBycode(domain.getSoilCorrosionRate());
        // 绝对距离
        this.mileage = NumberUtil.toMeter(domain.getMileage());
        // 附近测试桩
        EqptCptestStation eqptCptestStationNagm = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getNagm());
        this.nagm = eqptCptestStationNagm==null ? null : eqptCptestStationNagm.getCustomNumber();
        // 附近测试桩距离
        this.nagmMileage = NumberUtil.toMeter(domain.getNagmMileage());
        // 检测日期
        this.testingDate = DateFormat.format(domain.getTestingDate());
        // 检测单位
        this.testingCompany = domain.getTestingCompany();

        super.fromDomain(domain.getId(), domain.getRecorder(), domain.getRecordTime(), domain.getRemarks());
    }

    public Page<ExinspSoilCorrVO> fromDomainList(Page<ExinspSoilCorr> domainList) {

        Page<ExinspSoilCorrVO> list = new Page<ExinspSoilCorrVO>();
        for (ExinspSoilCorr exinspSoilCorr : domainList) {
            ExinspSoilCorrVO exinspSoilCorrVO = new ExinspSoilCorrVO();
            exinspSoilCorrVO.fromDomain(exinspSoilCorr);
            list.add(exinspSoilCorrVO);
        }
        BaseVOUtil.converterPage(domainList, list);
        return list;
    }
}